﻿using Microsoft.Practices.EnterpriseLibrary.Caching;

namespace TfsReports.Web.Helpers
{
    public static class Cache
    {
        /// <summary>
        /// Gets the cache manager.
        /// </summary>
        /// <value>The cache manager.</value>
        private static ICacheManager CacheManager
        {
            get { return CacheFactory.GetCacheManager(); }
        }

        /// <summary>
        /// Gets the object with the specified key from the cache.
        /// </summary>
        /// <value>The cache manager.</value>
        public static T Get<T>(string key)
        {
            return (T)CacheManager.GetData(key);
        }

        /// <summary>
        /// Gets the object with the specified key from the cache.
        /// </summary>
        public static T Get<T>()
        {
            return Get<T>(typeof(T).FullName);
        }

        /// <summary>
        /// Adds the specified key and value to the cache.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public static void Add(string key, object value)
        {
            CacheManager.Add(key, value);
        }

        /// <summary>
        /// Adds the specified key and value to the cache.
        /// </summary>
        /// <param name="value">The value.</param>
        public static void Add(object value)
        {
            Add(value.GetType().FullName, value);
        }

        /// <summary>
        /// Removes the specified key from the cache.
        /// </summary>
        /// <param name="key">The key.</param>
        public static void Remove(string key)
        {
            CacheManager.Remove(key);
        }

        /// <summary>
        /// Removes the specified key from the cache.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public static void Remove<T>()
        {
            Remove(typeof(T).FullName);
        }

        /// <summary>
        /// Flushes this instance.
        /// </summary>
        public static void Flush()
        {
            CacheManager.Flush();
        }
    }
}
